﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Yoozoo.Mars.Got;

namespace Yoozoo.Core.Common
{
    public class UnityQualityListener : 
        QualityListenerMono<UnityQualityListener.UnityQualitySetting>,
        IRenderPrecisionAdjuster
    {
        [Serializable]
        public class UnityQualitySetting : QualitySetting
        {
            public int qualityLevel = 2;
            
            [Header("勾选后下面字段生效")]
            public bool overrideDefaultSetting = false;

            [Range(0,3)]
            public int textureQuality = 0;

            public SkinWeights skinWeights = SkinWeights.FourBones;
            
            public void Apply()
            {
                UnityEngine.QualitySettings.SetQualityLevel(qualityLevel);

                if (overrideDefaultSetting)
                {
                    UnityEngine.QualitySettings.globalTextureMipmapLimit = textureQuality;
                    UnityEngine.QualitySettings.skinWeights = skinWeights;
                    // etc...
                }
            }
        }

        public override void ChangeQualitySetting(UnityQualitySetting qualitySetting)
        {
            qualitySetting.Apply();
        }

        public void ChangeRenderPrecision(QualityEnum quality)
        {
            UnityQualitySetting qualitySetting = GetQualitySetting(quality);
            if (qualitySetting.overrideDefaultSetting)
            {
                UnityEngine.QualitySettings.globalTextureMipmapLimit = qualitySetting.textureQuality;
            }
        }
    }
}
